import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import dictEnum from "/@/enums/dictEnum"

export const columns: BasicColumn[] = [
  {
    title: "用户名称",
    dataIndex: "userName",
    width: 130,
    slot: "account",
    align: "left",
  },
  {
    title: "登录IP",
    dataIndex: "ip",
    width: 140,
  },
  {
    title: "登录地点",
    dataIndex: "location",
    width: 160,
  },
  {
    title: "浏览器",
    dataIndex: "browser",
    width: 100,
  },
  {
    title: "操作系统",
    dataIndex: "os",
    width: 100,
  },

  {
    title: "状态",
    dataIndex: "status",
    width: 60,
    customRender: ({ text }) => {
      const color = text == "2" ? "red" : text == "1" ? "green" : "gray"
      return render.renderTag(render.renderDict(text, dictEnum.LoginLogStatus), color)
    },
  },
  {
    title: "操作信息",
    dataIndex: "msg",
    width: 120,
  },
  {
    title: "登录日期",
    dataIndex: "loginTime",
    width: 150,
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "userName",
    label: "用户名称",
  },
  {
    field: "terminalName",
    label: "终端",
  },
  {
    field: "grantTypeName",
    label: "授权方式",
  },
  {
    field: "ip",
    label: "登录IP",
  },
  {
    field: "location",
    label: "登录地点",
  },
  {
    field: "browser",
    label: "浏览器",
  },
  {
    field: "os",
    label: "操作系统",
  },
  {
    field: "status",
    label: "状态",
    render: (curVal, data) => {
      const color = curVal == "2" ? "red" : curVal == "1" ? "green" : "gray"
      return render.renderTag(render.renderDict(curVal, dictEnum.LoginLogStatus), color)
    },
  },
  {
    field: "msg",
    label: "操作信息",
  },
  {
    field: "loginTime",
    label: "登录日期",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "userName",
    label: "用户名称",
    component: "Input",
    colProps: { span: 8 },
  },
  {
    field: "status",
    label: "登录状态",
    component: "JDictSelectTag",
    componentProps: {
      dictType: dictEnum.LoginLogStatus,
      stringToNumber: true,
    },
    colProps: { span: 8 },
  },
  {
    field: "loginTime",
    component: "RangePicker",
    label: "登录时间",
    componentProps: {
      valueType: "Date",
    },
    colProps: {
      span: 8,
    },
  },
]
